import type { Metadata } from "next";
import localFont from "next/font/local";
import { auth } from "@/auth";
import {
  SidebarInset,
  SidebarProvider,
  SidebarTrigger,
} from "@/components/ui/sidebar";
import ThemeProviderWrap from "@/components/theme-providers";

import { redirect } from "next/navigation";
import "./globals.css";
import { SessionProvider } from "next-auth/react";
import { Suspense } from "react";
export const dynamic = "force-dynamic";
const geistSans = localFont({
  src: "./fonts/GeistVF.woff",
  variable: "--font-geist-sans",
  weight: "100 900",
});
const geistMono = localFont({
  src: "./fonts/GeistMonoVF.woff",
  variable: "--font-geist-mono",
  weight: "100 900",
});

export const metadata: Metadata = {
  title: "Price App",
  description: "Generated by X-CC studio",
};

const HEADER_HEIGHT = "4rem";
interface RootLayoutProps {
  children: React.ReactNode;
}

export default async function RootLayout({
  children,
}: Readonly<RootLayoutProps>) {
  let session = null;
  try {
    session = await auth();
  } catch (err) {
    console.log(err);
    redirect("/auth/login");
  }

  return (
    <html suppressHydrationWarning>
      <body
        className={`${geistSans.variable} ${geistMono.variable} antialiased overflow-hidden`}
        style={
          {
            "--header-height": HEADER_HEIGHT,
          } as React.CSSProperties
        }
      >
        <ThemeProviderWrap>
          <SessionProvider session={session}>
            <Suspense>{children}</Suspense>
          </SessionProvider>
        </ThemeProviderWrap>
      </body>
    </html>
  );
}
